class LevelElementView extends egret.Sprite {
    public constructor() {
        super();
        this.init();
    }

    public eltype: string = ""; // 代表元素类别

    public set num(value: number) {
        if (value <= 0) {
            // 已经没了，显示对号
            if (!this.checkmarkbit) {
                this.checkmarkbit = new egret.Bitmap();
                this.checkmarkbit.texture = RES.getRes("checkmark_png");
                this.checkmarkbit.x = (this.bitmap.width - this.checkmarkbit.width) / 2;
                this.checkmarkbit.y = this.bitmap.height + this.bitmap.y - this.checkmarkbit.height;
                this.addChild(this.checkmarkbit);
                this.removeChild(this.bittext);
            }
        } else {
            this.bittext.text = value.toString();
        }
    }

    public get num(): number {
        return Number(this.bittext.text);
    }

    private bitmap: egret.Bitmap; // 元素图
    private checkmarkbit: egret.Bitmap; // 对勾图
    private bittext: egret.BitmapText;

    private init() {
        this.touchChildren = false;
        if (!this.bitmap) {
            this.bitmap = new egret.Bitmap();
        }
        let bitwidth: number = (GameData.stageH - 40) / GameData.MaxColumn;
        this.bitmap.width = bitwidth;
        this.bitmap.height = bitwidth;
        this.addChild(this.bitmap);

        this.bittext = new egret.BitmapText();
        this.bittext.font = RES.getRes("number_fnt");
        this.bittext.text = "0";
        this.bittext.x = (bitwidth - this.bittext.width) / 2;
        this.bittext.y = this.bitmap.height + this.bitmap.y - this.bittext.height / 2;
        this.addChild(this.bittext);
    }

    public setTexture(value: string) {
        this.bitmap.texture = RES.getRes(value);
    }
}